<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <!--  引入vue.js  因为Element UI 依赖vue -->
    <script src="../static/js/vue.js"></script>
    <script src="../static/js/axios.js"></script>

    <link rel="stylesheet" href="../static/elementui/theme-chalk/index.css"/>
    <script src="../static/elementui/index.js"></script>
    <style type="text/css">
        #all{
            width:1500px;
            margin: 0 auto;
            margin-top: 55px;
        }
        #search_bar{
            height:200px;
            background-color:#eeeeee;
            text-align:center;
            line-height:80px;
            margin-top: 10px;
        }
        .star{
            color:red;
        }
        .div_out {
            margin-top: 15px;
        }
        .div_inner{
            position: relative;
            font-size: 14px;
            display: inline-block;
        }
        .content{
            width:500px;
            height:300px;
            border: 1px solid;
        }
        .span{
            display: inline-block;
            margin-left: 15px;
        }
    </style>
</head>
<body>
<div id="all">
    学员查询
    <el-divider></el-divider>
    <el-card class="box-card">
        <div id="search_bar">
            <div class="div_out">
                <div class="span">
                    <span class="star">*</span> 学员姓名：
                    <div class="div_inner">
                        <el-input v-model="stuName" id="studentName" placeholder="请输入关键字"></el-input>
                    </div>
                </div>

                <div class="span">
                    <span class="star">*</span> 手机号：
                    <div class="div_inner">
                        <el-input v-model="telephone" id="telephone" placeholder="请输入关键字"></el-input>
                    </div>
                </div>


                <div class="span">
                     <span class="star">*</span> 性别：
                         <el-select v-model="gender" placeholder="请选择">
                             <el-option
                                     v-for="item in gender_options"
                                     :key="item.value"
                                     :label="item.value"
                                     :value="item.value">
                             </el-option>
                         </el-select>
                 </div>
                <div class="span">
                    <span class="star">*</span> 身份：
                    <div class="div_inner">
                        <template>
                            <!--显示字符串？？-->
                            <el-select v-model="statusList.id" clearable @change="selectTrigger(statusList.id)" placeholder="请选择">
                                <el-option v-for="item in statusList" :key="item.value" :label="item.statusName"
                                           :value="item.id">
                                </el-option>
                            </el-select>
                        </template>
                    </div>
                </div>
                <br>
                <div class="span">
                    <span class="star">*</span> 是否为线下学员：
                    <el-select v-model="offline" placeholder="请选择">
                        <el-option v-for="item in offline_options" :key="item.value" :label="item.value" :value="item.value">
                        </el-option>
                    </el-select>
                </div>
                <div class="span">
                    <span class="star">*</span> 注册时间：
                    <div class="div_inner">
                        <el-date-picker value-format="yyyy/MM/dd" v-model="signInTime1" clearable @change="selectTrigger2(signInTime1)" type="date" placeholder="选择日期">
                        </el-date-picker>
                    </div>
                </div>

                <div class="span">
                    <el-button type="primary" size="small" @click="getAdminList">查询</el-button>
                </div>

                <div class="span">
                    <el-button type="primary" size="small" @click="reset">重置</el-button>
                </div>
            </div>
        </div>
        <template>
                <el-table
                        :data="tableData"
                        style="width: 100%"
                        :row-class-name="tableRowClassName">
                    <el-table-column type="index" label="序号" align="center" width="50">
                    </el-table-column>
                    <el-table-column prop="id" label="学号" align="center" width="100">
                    </el-table-column>
                    <el-table-column prop="stuName" label="学员姓名" align="center" width="180">
                    </el-table-column>
                    <el-table-column prop="signInTime" label="注册时间" align="center" width="180" :formatter="formatDate">
                    </el-table-column>
                    <el-table-column prop="telephone" label="手机号" align="center" width="180">
                    </el-table-column>
                    <el-table-column prop="stuLoginName" label="昵称" align="center" width="160">
                    </el-table-column>
                    <el-table-column prop="gender" label="性别" align="center" width="90">
                    </el-table-column>
                    <el-table-column prop="statusBean.statusName" label="身份" align="center" width="160">
                    </el-table-column>
                    <el-table-column prop="offline" label="是否是线下学员" align="center" width="180">
                    </el-table-column>
                    <el-table-column fixed="right" prop="manager" label="操作" align="center" width="150">
                        <template slot-scope="scope">
                            <el-button @click="handleClick(scope.row)" type="text" size="mini" >
                                查看
                            </el-button>
                            <el-button type="text" size="mini" @click="editorShow(scope.row)">编辑</el-button>
                            <el-button @click="del(scope.row,scope.$index)" type="text"  size="small">删除</el-button>
                            <!-- <el-button type="info" @click="dialogTableVisible = true" icon="el-icon-view" circle
                                size="mini"></el-button>
                            <el-button type="success" icon="el-icon-edit" circle size="mini"></el-button>
                            <el-button type="danger" icon="el-icon-delete" circle size="mini"></el-button> -->
                        </template>
                    </el-table-column>
                </el-table>
        </template>
            <!-- 分页组件 -->
            <div class="block" style="margin-top: 20px;">
                <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange"
                               :current-page="currentPage"
                               :page-sizes="[6, 12, 20]"
                               :page-size="6"
                               layout="total, sizes, prev, pager, next, jumper"
                               :total=total>
                </el-pagination>
            </div>
    </el-card>


    <!-- 编辑学生信息弹窗 -->
    <el-dialog title="编辑学员信息" :visible.sync="dialogFormVisible">
        <el-form :model="form">
            <el-form-item label="学员名称" :label-width="formLabelWidth">
                <el-input v-model="form.stuName" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="学员登录名" :label-width="formLabelWidth">
                <el-input v-model="form.stuLoginName" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="电话" :label-width="formLabelWidth">
                <el-input v-model="form.telephone" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="是否是线下学生" :label-width="formLabelWidth">
                <el-input v-model="form.offline" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="角色选择" :label-width="formLabelWidth">
                <el-select v-model="form.statusId"
                           placeholder="请选择">
                    <el-option v-for="item in statusList" :key="item.value" :label="item.statusName"
                               :value="item.id">
                    </el-option>
                </el-select>
            </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button @click="dialogFormVisible = false">取 消</el-button>
            <el-button type="primary" @click="updateAdminMsg">确 定</el-button>
        </div>
    </el-dialog>
</div>

<script>
    let vm = new Vue({
        el: "#all",
        data: {
            pageSize: 6,
            pageNum: 1,
            total: 0,
            dialogTableVisible: false,
            tableData: [],
            id:'',
            stuName:'',
            telephone: "",
            statusList: [],
            statusId:'',
            offline_options: [{
                value: '是',
                label: '1'
            }, {
                value: '否',
                label: '2'
            }],
            offline: '',
            gender_options: [{
                value: '男',
                label: '1'
            }, {
                value: '女',
                label: '2'
            }],
            gender: '',
            signInTime:'',
            signInTime1:null,
            dialogFormVisible: false,
            newAdminFormVisible:false,
            form: {
                stuName: '',
                stuLoginName: '',
                password: '',
                studentId: '',
                telephone:'',
                offline:'',
                statusId: '',
            },
            formLabelWidth: '120px',
        },
        created() {
            this.getAdminList();
            this.getStatusList();
        },
        methods: {
            //时间格式化
            formatDate:function(row, column) {
                // 获取单元格数据
                let data = row[column.property]
                // if (this.$MyComm.isEmpty(data)) {
                // 	return ''
                // }
                let dt = new Date(data)
                return dt.getFullYear() + '-' + (dt.getMonth() + 1) + '-' + dt.getDate()
            },
            //监听每页条数改变
            handleSizeChange(val) {
                this.pageSize = val;
                this.getAdminList();
                console.log(`每页 ${val} 条`);
            },
            //监听当前页改变
            handleCurrentChange(val) {
                console.log(`当前页: ${val}`);
                this.pageNum = val;
                this.getAdminList();
            },
            getStatusList() {
                axios.get("../status/findAll")
                    .then(res => {
                        console.log(res.data)
                        this.statusList = res.data.data;
                    })
                    .catch(error => {
                        console.log(error)
                    })
            },
            getAdminList() {
                axios.get('../student/findList', {
                    params: {
                        pageSize: this.pageSize,
                        pageNum: this.pageNum,
                        stuName:this.stuName,
                        telephone: this.telephone,
                        statusId:this.statusId,
                        offline:this.offline,
                        gender:this.gender,
                        signInTime:this.signInTime1
                    }
                })
                    .then(res => {//此处一定要用 箭头函数  不然this 就不是this
                        console.log(res.data.data.data);
                        this.total = res.data.data.total;
                        this.tableData = res.data.data.data;
                    })
                    .catch(error => {
                        console.log(error);
                    });

            },
            selectTrigger(val) {
                this.statusId = val;
              /*  this.getAdminList();*/
            },
            selectTrigger2(val) {
                this.signInTime1 = val;
              /*  this.getAdminList();*/
            },
            reset() {
                this.stuName = ''
                this.telephone = ''
                this.offline = ''
                this.gender = ''
             /*   this.statusList.id = ''*/
             /*   this.signInTime1 = ''*/
                this.getAdminList();
            },
            handleClick(row,index){
                window.parent.layui.index.openTabsPage('student/studentdetail'+"?id="+row.id,"学员详情")
            },
            //弹出窗体展示数据使用的方法
            editorShow(row) {
                this.form.stuName = row.stuName
                this.form.stuLoginName = row.stuLoginName
                this.form.telephone = row.telephone
                this.form.studentId = row.id
                this.form.offline = row.offline
                this.form.statusId = row.statusBean.id
                this.dialogFormVisible = true;
            },
            del(row,index) { //删除
                this.$confirm('此操作将永久删除该学生, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    axios({
                        method: 'DELETE',
                        url: '../student/del/'+ row.id,
                    }).then(res =>{
                        if(res.data.code ===200 ){
                            //删除当前选中行
                            // console.log(vm.tableData);
                            vm.tableData.splice(index,1);
                            this.$message({
                                type: 'success',
                                message: '删除成功!'
                            });
                        }else{
                            this.$message({
                                message:res.data.message
                            })
                        }
                    })
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    });
                });
            },
            updateAdminMsg(){
                axios({
                    method: 'PUT',
                    url: '../student/updateMsg',
                    // headers: {'Content-Type': 'application/x-www-form-urlencoded'},
                    params: {
                        stuName:this.form.stuName,
                        stuLoginName: this.form.stuLoginName,
                        telephone: this.form.telephone,
                        offline: this.form.offline,
                       /* this.form.statusId = row.statusBean.id*/
                        statusId:this.form.statusId,
                        id: this.form.studentId,
                    },

                }).then(res => {
                    if (res.data.code === 200) {
                        this.$message({
                            message: '修改成功',
                            type: 'success'
                        })
                        //关闭窗口
                        this.getAdminList()
                        this.dialogFormVisible=false
                    } else {
                        this.$message({
                            message: '系统繁忙',
                            type: 'error'
                        })
                    }
                }).catch(error => {
                    console.log(error);
                });
            },

        }
    })
</script>

</body>
</html>